import React from 'react';
import {
  IWelcomeReducerState,
  IWelcomeReducerAction,
} from '..//type';

export const useWelcomeReducer = () => {
  const reducer = (
    state: IWelcomeReducerState,
    action: IWelcomeReducerAction,
  ) => {
    switch (action?.type) {
      case 'update-isDraggable':
        return {
          ...state,
          isDraggable: action.payload,
        };
      case 'update-isResizable':
        return {
          ...state,
          isResizable: action.payload,
        };
      case 'update-layoutInfo':
        return {
          ...state,
          layoutInfo: action.payload,
        };
      default:
        return {
          ...state,
        };
    }
  };

  const INIT_STATE: IWelcomeReducerState = {
    isDraggable: false,
    isResizable: false,
    layoutInfo: {
      lg: [],
    },
  };

  const [state, commonDispatch] = React.useReducer(reducer, INIT_STATE);

  return {
    ...state,
    commonDispatch,
  };
};
